package servlet;

import java.io.IOException;
import java.text.*;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Company;
import bean.MaintainInfo;
import dao.CompanyDao;
import dao.MaintainDao;

public class AddMainInfoServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		String maintainer=request.getParameter("maintainer");
		String keyboarder=request.getParameter("keyboarder");
		String companyName=request.getParameter("companyName");
		String contents=request.getParameter("contents");
		String maindate=request.getParameter("maindate");
		   DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
		   Date mdate = null;
		try {
			mdate = df.parse(maindate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		 MaintainInfo minfo=new MaintainInfo();
		 minfo.setMaintainer(maintainer);
		 minfo.setKeyboarder(keyboarder);
		 minfo.setCompanyName(companyName);
		 minfo.setContents(contents);
		 minfo.setMaindate(mdate);
		
         MaintainDao mdao=new MaintainDao();
		
	
		     mdao.addMain(minfo);
		     request.setAttribute("","添加成功");		     
		     request.getRequestDispatcher("/Branch/SysMainManage.jsp").forward(request,response);
		
	
	}

}
